@tool
class_name LogicalEffect_Expression
extends LogicalEffectBase

#region 属性
# 表达式
@export var instance:Node
var expression:String = ""
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
#endregion
#region 公共方法
func init_effect(manager:LogicalEffectComponent):
	super.init_effect(manager)
## 应用
func apply():
	super.apply()
	var temp_expression := Expression.new()
	var input_names = []
	var parse_result = temp_expression.parse(expression,input_names)
	if parse_result != OK:
		push_error("Expression parse error: " + temp_expression.get_error_text() + " for expression " + expression)
		return false
	var input_values = []
	for input_name in input_names:
		pass
	var result = temp_expression.execute(input_values,instance)
	if temp_expression.has_execute_failed():
		push_error("Expression execute error: " + temp_expression.get_error_text() + " for expression: " + expression)
		return false
	if typeof(result) != TYPE_BOOL:
		push_error("Expression result is not boolean")
		return false
	return result
## 移除
func remove():
	super.remove()
## 更新
func update():
	super.update()
## 刷新
func refresh():
	super.refresh()
## 完成
func complete():
	super.complete()
func can_trigger() -> bool:
	return super.can_trigger()
func get_life_state() -> bool:
	return super.get_life_state()
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _get_property_list() -> Array[Dictionary]:
	var properties:Array[Dictionary] = []
	properties.append({
		"name":"expression",
		"type":TYPE_STRING,
		"usage":PROPERTY_USAGE_DEFAULT,
		"hint":PROPERTY_HINT_EXPRESSION,
	})
	return properties
#endregion

